{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello there, Ryan Mitchell!\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "params = {'firstname': 'Ryan', 'lastname': 'Mitchell'}\n",
    "r = requests.post(\n",
    "    'https://pythonscraping.com/pages/files/processing.php',\n",
    "    params)\n",
    "print(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"status\":\"0\",\"errmsg\":\"You have already subscribed.\"}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "params = {\n",
    "    'firstname': 'Ryan',\n",
    "    'lastname': 'Mitchell',\n",
    "    'email': 'ryanemitchell@gmail.com',\n",
    "    'action': 'eclg_add_newsletter'\n",
    "}\n",
    "r = requests.post('https://pythonscraping.com/wp-admin/admin-ajax.php',\n",
    "                   params)\n",
    "print(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sorry, there was an error uploading your file.\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "files = {'uploadFile': open('logo.jpg', 'rb')}\n",
    "r = requests.post('http://pythonscraping.com/pages/processing2.php', files=files)\n",
    "print(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "<h2>Welcome to the Website!</h2>\n",
      "You have logged in successfully! <br><a href=\"profile.php\">Check out your profile!</a>\n",
      "Cookie is set to:\n",
      "{'loggedin': '1', 'username': 'Ryan'}\n",
      "Going to profile page...\n",
      "Hey Ryan! Looks like you're still logged into the site!\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "params = {'username': 'Ryan', 'password': 'password'}\n",
    "r = requests.post(\n",
    "    'https://pythonscraping.com/pages/cookies/welcome.php',\n",
    "    params)\n",
    "print(r.text)\n",
    "\n",
    "print('Cookie is set to:')\n",
    "print(r.cookies.get_dict())\n",
    "print('Going to profile page...')\n",
    "r = requests.get('https://pythonscraping.com/pages/cookies/profile.php', \n",
    "                 cookies=r.cookies)\n",
    "print(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cookie is set to:\n",
      "{'loggedin': '1', 'username': 'Ryan'}\n",
      "Going to profile page...\n",
      "Hey Ryan! Looks like you're still logged into the site!\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "session = requests.Session()\n",
    "\n",
    "params = {'username': 'Ryan', 'password': 'password'}\n",
    "s = session.post('https://pythonscraping.com/pages/cookies/welcome.php', params)\n",
    "print('Cookie is set to:')\n",
    "print(s.cookies.get_dict())\n",
    "print('Going to profile page...')\n",
    "s = session.get('https://pythonscraping.com/pages/cookies/profile.php')\n",
    "print(s.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<p>Hello ryan.</p><p>You entered password as your password.</p>\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "from requests.auth import AuthBase\n",
    "from requests.auth import HTTPBasicAuth\n",
    "\n",
    "auth = HTTPBasicAuth('ryan', 'password')\n",
    "r = requests.post(\n",
    "    url='https://pythonscraping.com/pages/auth/login.php', auth=auth)\n",
    "print(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
